<?php

namespace App\Http\Controllers\OpenShop\Merchant;

use App\Http\Controllers\BaseController;
use App\Remote\Rms\RmsUserRemote;
use App\Service\OpenShop\SiteLocation\AuthService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AppController extends BaseController
{
    /**
     * @throws GuzzleException
     */
    public function getMerchantLoginJwt(Request $request): JsonResponse
    {
        $ip          = (string)$request->ip();
        $authUser    = AuthService::getRmsUserInfo($request);
        $rmsUserId   = $authUser['userId'] ?? 0;

        $jwt = RmsUserRemote::getMerchantLoginJwt($rmsUserId, $ip);

        return $this->success($jwt);
    }

}